package com.tanhua.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.SettingsVo;
import com.tanhua.service.SettingsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/users")
public class SettingsController {

    @Autowired
    private SettingsService settingsService;


    /**
     * 通用设置
     * @return
     */
    @GetMapping("/settings")
    public ResponseEntity setting(){
        SettingsVo settingsVo = settingsService.Settings();
        return ResponseEntity.ok(settingsVo);
    }


    /**
     * 保存好友问题设置
     * @param map
     * @return
     */
    @PostMapping("/questions")
    public ResponseEntity question(@RequestBody Map map){
        //获取content参数
        String content = (String) map.get("content");
        settingsService.SaveQuestion(content);
        return ResponseEntity.ok(null);
    }

    /**
     * 修改用户通知设置
     * @param map
     * @return
     */
    @PostMapping("/notifications/setting")
    public ResponseEntity setting(@RequestBody Map map){
        settingsService.updateSetting(map);
        return ResponseEntity.ok(null);
    }

    /**
     * 黑名单查看
     * @return
     */
    @GetMapping("/blacklist")
    public  ResponseEntity BlackList(@RequestParam(defaultValue = "1") int page,@RequestParam(defaultValue = "10") int size){
      PageResult pageResult =  settingsService.BlackListSelect(page,size);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 删除黑名单
     * @param black_uid
     * @return
     */
    @DeleteMapping("/blacklist/{uid}")
    public ResponseEntity deleteBlackList(@PathVariable("uid") Long black_uid){
        settingsService.deleteBlackList(black_uid);
        return ResponseEntity.ok(null);
    }

    /**
     * 修改手机号- 1 发送短信验证码
     * @return
     */
    @PostMapping("/phone/sendVerificationCode")
    public ResponseEntity sendVerificationCode(){
        settingsService.sendVerificationCode();
        return ResponseEntity.ok(null);
    }

    /**
     * 修改手机号 - 2 校验验证码
     * @param map
     * @return
     */
    @PostMapping("/phone/checkVerificationCode")
    public ResponseEntity checkVerificationCode(@RequestBody Map map){
        String verificationCode = (String) map.get("verificationCode");
        Map re  = settingsService.checkVerificationCode(verificationCode);
        return ResponseEntity.ok(re);
    }

    /**
     * 修改手机号 - 3 保存
     * @param map
     * @return
     */
    @PostMapping("/phone")
    public ResponseEntity updatePhone(@RequestBody Map map){
        String mobile = (String) map.get("phone");
        settingsService.updatePhone(mobile);
        return ResponseEntity.ok(null);
    }
    }
